{% extends "domain_base.html" %}
{% block domain_content %}
<form method="post">
<div class="section">
  <div class="section__header">
    <h1 class="section__title">{{ _('{0}: Permissions').format(domain.name) }}</h1>
  </div>
  {% if roles.length == 3 %}
    <div class="section__body typo">
      <blockquote class="warn">
        <p>{{ _("The 'default' role applies to ALL REGISTERED USER.")|safe }}</p>
        <p>{{ _("You may want to create a new role in 'Manage Role' page.")|safe }}</p>
      </blockquote>
    </div>
  {% endif %}
  <div class="section__body no-padding domain-users">
    <table class="data-table">
      <colgroup>
        <col class="col--description">
        {%- for role in roles -%}
          <col class="col--p">
        {%- endfor -%}
      </colgroup>
      <thead>
        <tr>
          <th class="col--description">{{ _('Permissions') }}</th>
          {%- for role in roles -%}
            <th class="col--p"><span data-tooltip="{{ role._id }}">{{ role._id }}</span></th>
          {%- endfor -%}
        </tr>
      </thead>
      {%- for family, perms in PERMS_BY_FAMILY -%}
        <tbody>
          <tr><td class="col--family" colspan="{{ (roles|length)+1 }}">{{ _(family) }}</td></tr>
          {%- for perm in perms -%}
            <tr>
              <td class="col--description">{{ _(perm.desc) }}</td>
              {%- for role in roles -%}
                <td class="col--p">
                  <label class="compact checkbox">
                    <input name="{{ role._id }}" data-checkbox-group="{{ role._id }}" data-checkbox-range value="{{ log2(perm.key) }}" type="checkbox"{% if role.perm|bitand(perm.key) %} checked{% endif %}{% if role._id == 'root' %} disabled{% endif %}>
                  </label>
                </td>
              {%- endfor -%}
            </tr>
          {%- endfor -%}
        </tbody>
      {%- endfor -%}
        <tbody style="display:none">
          <tr><td class="col--family" colspan="{{ (roles|length)+1 }}">placeholder</td></tr>
          <tr>
            <td class="col--description">placeholder</td>
            {%- for role in roles -%}
              <td class="col--p">
                <label class="compact checkbox">
                  <input name="{{ role._id }}" data-checkbox-group="{{ role._id }}" data-checkbox-range value="1000" type="checkbox" checked{% if role._id == 'root' %} disabled{% endif %}>
                </label>
              </td>
            {%- endfor -%}
          </tr>
        </tbody>
    </table>
  </div>
  <div class="section__body">
    <button class="rounded primary button" role="submit">
      {{ _('Update Permission') }}
    </button>
    <button type="button" class="rounded button" onclick="window.history.go(-1)">
      {{ _('Cancel') }}
    </button>
  </div>
</div>
</form>
{% endblock %}
